/**
 * 		ConnectionsManager.java
 *  Adrián E. Córdoba 		04/05/2014
 */
package ar.com.adriancordoba.app.enterprise.rosc.model.connections;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.jboss.logging.Logger;

/**
 * 
 * @author Adrián E. Córdoba
 */
public class ConnectionsManager {
	private static Logger logger = Logger.getLogger(ConnectionsManager.class);
	
	public static Connection getConnection(){
		Connection connection = null;
		try {
			Context initialContext = new InitialContext();
			DataSource dataSource = (DataSource)initialContext.lookup("java:jboss/datasources/ROSC");
			connection = dataSource.getConnection();
		} catch (NamingException e) {
			logger.error("Cannot get initial context.");
		} catch (SQLException e) {
			logger.error("Cannot get connection to datasource 'ROSC'.");
		}
		return connection;
	}
}
